using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using System;

public static class TaskUtil 
{
    public static async void StartSingleIfNotRunning(Func<bool> getStorage, Action<bool> setStorage, Func<Task> runTask)
    {
        if(getStorage.Invoke() == true)
        {
            return;
        }
        var task = runTask.Invoke();
        setStorage.Invoke(true);
        try
        {
            await task;
        }
        finally
        {
            setStorage.Invoke(false);
        }
        
    }
}
